package cn.gson.springboot.controller.aftercontroller;

import cn.gson.springboot.model.pjos.Target;
import cn.gson.springboot.model.service.afterservice.TargetService;
import cn.gson.springboot.model.vo.aftervo.*;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/tar")
public class TargetController {

    @Autowired
    TargetService sc;

    @RequestMapping("/list-info")
    @ResponseBody
    public List<TargetFinishVo> listInfo(Integer date){
        List<TargetFinishVo> list = sc.finishValue(date);
        return list;
    }

    @RequestMapping("/first-info")
    @ResponseBody
    public List<TargetFinishVo> firstInfo(Integer date){
        List<TargetFinishVo> list = sc.firstValueFinish(date);
        return list;
    }

    @RequestMapping("/first-details")
    @ResponseBody
    public List<TargetVo> firstDetails(Integer date, Integer month){
        List<TargetVo> list = sc.firstYearValueFinishDetails(date,month);
        return list;
    }

    @RequestMapping("/second-info")
    @ResponseBody
    public List<TargetFinishVo> secondInfo(Integer date){
        List<TargetFinishVo> list = sc.secondValueFinish(date);
        return list;
    }

    @RequestMapping("/third-info")
    @ResponseBody
    public List<TargetFinishVo> thirdInfo(Integer date){
        List<TargetFinishVo> list = sc.thirdValueFinish(date);
        return list;
    }

    @RequestMapping("/check-month")
    @ResponseBody
    public List<TargetVo> checkMonth(Integer date){
        return sc.selectByMonth(date);
    }

    @RequestMapping("/check-target")
    @ResponseBody
    public List<TargetVo> checkTarget(Integer data, Integer month){
        return sc.selectTarget(data,month);
    }

    @RequestMapping("/target-name")
    @ResponseBody
    public List<String> targetName(Integer data, Integer month){
        return sc.selectTargetByName(data,month);
    }

    @RequestMapping("/target-value")
    @ResponseBody
    public List<Double> targetValue(Integer data, Integer month){
        return sc.selectTargetValue(data,month);
    }

    @RequestMapping("/target-finish")
    @ResponseBody
    public List<Double> targetFinish(Integer data, Integer month){
        return sc.selectTargetFinish(data,month);
    }

    @RequestMapping("/target-percent")
    @ResponseBody
    public List<Double> targetPercent(Integer data, Integer month){
        return sc.selectTargetPercent(data,month);
    }

    @RequestMapping("/dept-emp")
    @ResponseBody
    public List<DeptVo> deptEmp(){
        return sc.selectDeptEmp();
    }

    @RequestMapping("/save-target")
    @ResponseBody
    public void saveTarget(@RequestBody TargetSaveVo tar){
        sc.addTarget(tar);
    }

    @RequestMapping("/tare-date")
    @ResponseBody
    public Map<String,Object> tareDate(String time, String empName, Integer currPage, Integer pageSize){
        Page<Object> obj = PageHelper.startPage(currPage, pageSize);
        List<Target> tare = sc.selectTareByDate(time, empName);

        Map<String,Object> map = new HashMap<>();
        map.put("rows",obj.getResult());        //分页后的数据，一页展示多少数据
        map.put("total",obj.getTotal());        //总条数
        return map;     //总条数
    }

    @RequestMapping("/update-tare")
    @ResponseBody
    public void updateTare(Integer goalId, double goalValue){
        sc.updateTarget(goalId, goalValue);
    }

    @RequestMapping("/emp-date")
    @ResponseBody
    public List<Integer> empDate(Integer empId, Integer date){
        return sc.selectEmpByDate(empId, date);
    }

    @RequestMapping("/date-max")
    @ResponseBody
    public Integer dateMax(Integer empId, Integer date){
        return sc.selectDateByMax(empId, date);
    }

    @RequestMapping("/chart-name")
    @ResponseBody
    public List<String> chartName(Integer date, Integer month){
        return sc.selectChartByName(date, month);
    }

    @RequestMapping("/chart-value")
    @ResponseBody
    public List<Double> chartValue(Integer date, Integer month){
        return sc.selectChartByValue(date, month);
    }

    @RequestMapping("/chart-finish")
    @ResponseBody
    public List<Double> selectChartByFinish(Integer date, Integer month){
        return sc.selectChartByFinish(date, month);
    }

    @RequestMapping("/chart-percent")
    @ResponseBody
    public List<Double> chartPercent(Integer date, Integer month){
        return sc.chartValueFinish(date, month);
    }

    @RequestMapping("/dept-value")
    @ResponseBody
    public List<PieDoubleVo> deptValue(Integer date, Integer month){
        return sc.selectDeptValue(date, month);
    }

    @RequestMapping("/dept-finish")
    @ResponseBody
    public List<PieDoubleVo> deptFinish(Integer date, Integer month){
        return sc.selectDeptFinish(date, month);
    }
}
